package com.network.topo.snmp;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import org.snmp4j.Target;

import com.network.util.snmp4j.SnmpGet;
import com.network.util.snmp4j.SnmpGetResultSet;

public class TmnxOamPingResultsTable extends AbstractXxxTable {
	private static ArrayList<String> oidList = null;
	private HashMap<Object, RowData> objDataMap = new HashMap<Object, RowData>();
	private HashMap<Object, RowData> indexDataMap = new HashMap<Object, RowData>();
	private int rowCount = 0;

	private TmnxOamPingResultsTable(SnmpGetResultSet resultSet)
	{
		this.resultSet = resultSet;
		if (this.resultSet != null)
		{
			rowCount = this.resultSet.getRowCount();
			for (int i = 0; i < rowCount; i++)
			{
				RowData rowData = new RowData();
				int oidIndex = 0;
				rowData.tmnxOamPingResultsAverageRtt = getValue(getOidList().get(oidIndex++), i);
				rowData.tmnxOamPingResultsProbeResponses = getValue(getOidList().get(oidIndex++), i);
				rowData.tmnxOamPingResultsRttSumOfSquares = getValue(getOidList().get(oidIndex++), i);
				rowData.tmnxOamPingResultsSentProbes = getValue(getOidList().get(oidIndex++), i);
				// rowData.ipAdEntBcastAddr =
				// str2int(getValue(getOidList().get(oidIndex++), i));
				// rowData.ipAdEntReasmMaxSize =
				// str2int(getValue(getOidList().get(oidIndex++), i));
				indexDataMap.put(i, rowData);
				//objDataMap.put(rowData.getIpAdEntAddr(), rowData);
				//objDataMap.put(rowData.getIpAdEntIfIndex(), rowData);
			}
		}
	}

	public static TmnxOamPingResultsTable getInstance(SnmpGet snmpGet, Target target)
	{
		SnmpGetResultSet sgrs = null;
		TmnxOamPingResultsTable instance = null;
		try
		{
			sgrs = snmpGet.query(getOidList(), target);
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		if (sgrs != null && sgrs.next() == true)
		{
			instance = new TmnxOamPingResultsTable(sgrs);
		}
		return instance;
	}

	public static synchronized ArrayList<String> getOidList()
	{
		if (oidList == null)
		{
			oidList = new ArrayList<String>();
			oidList.add("1.3.6.1.4.1.6527.3.1.2.11.1.4.1.6");
			oidList.add("1.3.6.1.4.1.6527.3.1.2.11.1.4.1.10");
			oidList.add("1.3.6.1.4.1.6527.3.1.2.11.1.4.1.7");
			oidList.add("1.3.6.1.4.1.6527.3.1.2.11.1.4.1.11");
			// oidList.add("1.3.6.1.2.1.4.20.1.4");
			// oidList.add("1.3.6.1.2.1.4.20.1.5");
		}
		return oidList;
	}

	public boolean isContains(String ipAddr)
	{
		boolean rtnCode = false;
		if (objDataMap.get(ipAddr) != null)
		{
			rtnCode = true;
		}
		return rtnCode;
	}

	public String getTmnxOamPingResultsAverageRtt(Object obj, boolean useIndex)
	{
		String rtnValue = "";
		RowData rowData = null;
		if (useIndex)
		{
			rowData = indexDataMap.get(obj);
		}
		else
		{
			rowData = objDataMap.get(obj);
		}
		if (rowData != null)
		{
			rtnValue = rowData.getTmnxOamPingResultsAverageRtt();
		}
		return rtnValue;
	}

	public String getTmnxOamPingResultsProbeResponses(Object obj, boolean useIndex)
	{
		String rtnValue = "";
		RowData rowData = null;
		if (useIndex)
		{
			rowData = indexDataMap.get(obj);
		}
		else
		{
			rowData = objDataMap.get(obj);
		}
		if (rowData != null)
		{
			rtnValue = rowData.getTmnxOamPingResultsProbeResponses();
		}
		return rtnValue;
	}

	public String getTmnxOamPingResultsRttSumOfSquares(Object obj, boolean useIndex)
	{
		String rtnValue = "";
		RowData rowData = null;
		if (useIndex)
		{
			rowData = indexDataMap.get(obj);
		}
		else
		{
			rowData = objDataMap.get(obj);
		}
		if (rowData != null)
		{
			rtnValue = rowData.getTmnxOamPingResultsRttSumOfSquares();
		}
		return rtnValue;
	}

	public String getTmnxOamPingResultsSentProbes(Object obj, boolean useIndex)
	{
		String rtnValue = "";
		RowData rowData = null;
		if (useIndex)
		{
			rowData = indexDataMap.get(obj);
		}
		else
		{
			rowData = objDataMap.get(obj);
		}
		if (rowData != null)
		{
			rtnValue = rowData.getTmnxOamPingResultsSentProbes();
		}
		return rtnValue;
	}
	public class RowData
	{
		private String tmnxOamPingResultsRttSumOfSquares = "";
		private String tmnxOamPingResultsAverageRtt = "";
		private String tmnxOamPingResultsProbeResponses = "";
		private String tmnxOamPingResultsSentProbes = "";
		
		public String getTmnxOamPingResultsAverageRtt() {
			return tmnxOamPingResultsAverageRtt;
		}
		public void setTmnxOamPingResultsAverageRtt(String tmnxOamPingResultsAverageRtt) {
			this.tmnxOamPingResultsAverageRtt = tmnxOamPingResultsAverageRtt;
		}
		public String getTmnxOamPingResultsProbeResponses() {
			return tmnxOamPingResultsProbeResponses;
		}
		public void setTmnxOamPingResultsProbeResponses(
				String tmnxOamPingResultsProbeResponses) {
			this.tmnxOamPingResultsProbeResponses = tmnxOamPingResultsProbeResponses;
		}
		public String getTmnxOamPingResultsRttSumOfSquares() {
			return tmnxOamPingResultsRttSumOfSquares;
		}
		public void setTmnxOamPingResultsRttSumOfSquares(
				String tmnxOamPingResultsRttSumOfSquares) {
			this.tmnxOamPingResultsRttSumOfSquares = tmnxOamPingResultsRttSumOfSquares;
		}
		public String getTmnxOamPingResultsSentProbes() {
			return tmnxOamPingResultsSentProbes;
		}
		public void setTmnxOamPingResultsSentProbes(String tmnxOamPingResultsSentProbes) {
			this.tmnxOamPingResultsSentProbes = tmnxOamPingResultsSentProbes;
		}
		
		
	}

	public int getRowCount()
	{
		return rowCount;
	}

	public void setRowCount(int rowCount)
	{
		this.rowCount = rowCount;
	}
}
